SHELL=/bin/sh
name=ACE
INCLUDE=-Iinclude/
LIB=$(shell geant4-config --libs)
C=g++ $(shell geant4-config --cflags)

.PHONY: all clean
all: $(shell ls src)
	$C -o $(name) $(name).cc build/* $(INCLUDE) $(LIB)
clean:
	rm -f build/*

define compilefile
$1:
ifneq ($(shell find src -newer build/$1.o -name "$1" 2>&1),)
	$C -c -o build/$1.o src/$1 $(INCLUDE)
endif
endef

$(foreach file, $(shell ls src), $(eval $(call compilefile,$(file))))